package com.ljy.controller.admin;

import com.ljy.dto.GoodsDTO;
import com.ljy.dto.LeaseDTO;
import com.ljy.dto.LeasePageDTO;
import com.ljy.entity.Lease;
import com.ljy.entity.RollImage;
import com.ljy.result.PageResult;
import com.ljy.result.Result;
import com.ljy.service.LeaseService;
import com.ljy.vo.GoodsVO;
import com.ljy.vo.LeaseVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/admin/lease")
public class LeaseController {
    @Autowired
    LeaseService leaseService;

    @PostMapping("/add")
    public Result addLease(@RequestBody LeaseDTO leaseDTO){
        leaseService.addLease(leaseDTO);
        return Result.success();
    }

    @GetMapping("/page")
    public Result<PageResult<LeaseVO>>pageSelect(LeasePageDTO dto){
        PageResult<LeaseVO> pageResult= leaseService.selectPage(dto);
        log.info("分页查询"+pageResult);
        return Result.success(pageResult);

    }

    @GetMapping("/{id}")
    public Result<Lease> selectById(@PathVariable Integer id){
        Lease lease = leaseService.selectById(id);
        return Result.success(lease);
    }

    @DeleteMapping
    public Result batchDelete(@RequestParam List<Integer> ids){
        leaseService.batchDelete(ids);
        return Result.success();
    }
    @PostMapping("/status/{status}")
    public Result changeStatus(@PathVariable Short status,Integer id){
        leaseService.changeStatus(status,id);
        return Result.success();
    }

    @PostMapping("/modify")
    public Result modifyGoods(@RequestBody LeaseDTO dto){
        leaseService.modifyLease(dto);
        return Result.success();
    }
    @PostMapping("/rollImage")
    public Result rollImageSubmit(@RequestBody List<RollImage> dto){
        leaseService.rollImageSubmit(dto);
        return Result.success();
    }
    @GetMapping("/rollImage")
    public Result<List<RollImage>> getRollImage(){
        List<RollImage> list=leaseService.getRollImage();
        return Result.success(list);
    }
}
